package com.example.cdctest.controller;

import com.example.cdctest.pojo.Question;
import com.example.cdctest.pojo.UserInfo;
import com.example.cdctest.pojo.WrongTopic;
import com.example.cdctest.service.QuestionService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/services")
public class ExaminationController {
    @Resource
    private QuestionService questionService;
    @RequestMapping("examination")
    public ModelAndView exmaination(HttpSession session) {
        ModelAndView modelAndView=new ModelAndView();
        List<Question> questions= questionService.selectAllQuestion();
        session.setAttribute("num",0);
        modelAndView.addObject("questions",questions);
        modelAndView.setViewName("services/examination");
        return modelAndView;
    }
    @RequestMapping("xiayitie")
    @ResponseBody
    public ModelAndView xiayitie(HttpSession session)
    {
        List<Question> questions= questionService.selectAllQuestion();
        Integer num= (Integer) session.getAttribute("num");
        if (num<questions.size()-1)
        {
            num=num+1;
        }
        else {
            num=num;
        }
        session.setAttribute("num",num);
        ModelAndView modelAndView=new ModelAndView();

        modelAndView.addObject("questions",questions);
        modelAndView.setViewName("services/question_type_examination_manage");
        return modelAndView;
    }
    @RequestMapping("shangyitie")
    @ResponseBody
    public ModelAndView shangyitie(HttpSession session)
    {
        List<Question> questions= questionService.selectAllQuestion();
        Integer num= (Integer) session.getAttribute("num");
        if (num>0)
        {
            num=num-1;
        }
        else
        {
            num=num;
        }
        session.setAttribute("num",num);
        ModelAndView modelAndView=new ModelAndView();

        modelAndView.addObject("questions",questions);
        modelAndView.setViewName("services/question_type_examination_manage");
        return modelAndView;
    }
    @RequestMapping("answersPaper")
    @ResponseBody
    public ModelAndView answersPaper(Integer count,HttpSession session)
    {
        List<Question> questions= questionService.selectAllQuestion();
        Integer num= (Integer) session.getAttribute("num");
        num=count-1;
        session.setAttribute("num",num);

        ModelAndView modelAndView=new ModelAndView();

        modelAndView.addObject("questions",questions);
        modelAndView.setViewName("services/question_type_examination_manage");
        return modelAndView;
    }
}
